

import bpy

import 全局控制.Node.插座.bl_插座基类 as 插座基类
from 节点.Core import bl_UI配色

import engine.initLIB.load_dll as engineLib
import ctypes






def f_socketF32Update(self, context):
	engineLib.flexCAPI.f_bl_插座传入数据(
		ctypes.c_wchar_p(self.node.id_data.name), 
		ctypes.c_wchar_p(self.node.name), 
		ctypes.c_wchar_p(self.identifier), 
		ctypes.py_object(float(self.default_value)),
		ctypes.c_bool(self.is_output)
	)
	
	if context :
		self.id_data.f_节点数据更新_更新树([self.node])



class C_Socket_节点流程阀(插座基类.C_Socket_基类):
	default_value = bpy.props.BoolProperty(default=True)
	def __init__(self):
		super(C_Socket_节点流程阀, self).__init__()

	def draw(self, context, layout, node, text):
		layout.label(text=text)
	def draw_color(self, context, node):
		return (0.6, 0.6, 0.3, 1.0)
		
	def f_getData(self):
		return None

	def f_setData(self):
		return None



class C_Socket_Bool(插座基类.C_Socket_基类):
	default_value = bpy.props.BoolProperty(default=False)
	def __init__(self):
		super(C_Socket_Bool, self).__init__()

	def draw(self, context, layout, node, text):
		layout.label(text=text)
	def draw_color(self, context, node):
		return (0.5, 0.5, 0.5, 0.5)
		
	def f_getData(self):
		return None

	def f_setData(self):
		return None









	
class C_Socket_F32(插座基类.C_Socket_基类):
	default_value = bpy.props.FloatProperty(default=0.0, update=f_socketF32Update)
	def __init__(self):
		super(C_Socket_F32, self).__init__()

	def draw(self, context, layout, node, text):
		if self.is_output == False and self.is_linked == False :
			layout.prop( self, 'default_value', text=text )
		else:
			layout.label(text="F32:"+text)
		
	def draw_color(self, context, node):
		return bl_UI配色.g_标量插座颜色
		
	def f_getData(self):
		if self.is_linked == False :
			return self.default_value
		return engineLib.flexCAPI.f_取插座数据(ctypes.c_wchar_p(self.node.id_data.name), ctypes.c_wchar_p(self.node.name), ctypes.c_wchar_p(self.identifier))
		
	def f_setData(self, data):
		self.default_value = float(data)
		f_socketF32Update(self, None)
		
	def f_update(self):
		f_socketF32Update(self, None)





class C_Socket_F64(插座基类.C_Socket_基类):
	default_value = bpy.props.FloatProperty(default=0.0, update=f_socketF32Update)
	def __init__(self):
		super(C_Socket_F64, self).__init__()

	def draw(self, context, layout, node, text):
		if self.is_output == False and self.is_linked == False :
			layout.prop( self, 'default_value', text=text )
		else:
			layout.label(text="F32:"+text)
		
	def draw_color(self, context, node):
		return bl_UI配色.g_标量插座颜色
		
	def f_getData(self):
		if self.is_linked == False :
			return self.default_value
		return engineLib.flexCAPI.f_取插座数据(ctypes.c_wchar_p(self.node.id_data.name), ctypes.c_wchar_p(self.node.name), ctypes.c_wchar_p(self.identifier))
		
	def f_setData(self, data):
		self.default_value = float(data)
		f_socketF32Update(self, None)
		
	def f_update(self):
		f_socketF32Update(self, None)





def f_socketInt32Update(self, context):
	engineLib.flexCAPI.f_bl_插座传入数据(
			ctypes.c_wchar_p(self.node.id_data.name), 
			ctypes.c_wchar_p(self.node.name), 
			ctypes.c_wchar_p(self.identifier), 
			ctypes.py_object(self.default_value),
			ctypes.c_bool(self.is_output)
	)
	#print('f_socketInt32Update = ', f_socketInt32Update, context, self)
	if context :
		self.id_data.f_节点数据更新_更新树([self.node])









class C_Socket_I8(插座基类.C_Socket_基类):
	default_value = bpy.props.IntProperty(default=0, min=-128, max=128)
	def __init__(self):
		super(C_Socket_I8, self).__init__()

	def draw(self, context, layout, node, text):
		if self.is_output == False and self.is_linked == False :
			layout.prop( self, 'default_value', text=text )
		else:
			layout.label(text='I8:'+text)
	def draw_color(self, context, node):
		return (0.5, 0.5, 0.5, 0.5)
		
	def f_getData(self):
		return None
	def f_setData(self):
		return None
	def f_update(self):
		f_socketF32Update(self, None)





class C_Socket_I32(插座基类.C_Socket_基类):
	default_value = bpy.props.IntProperty(default=0, update=f_socketInt32Update)
	def __init__(self):
		super(C_Socket_I32, self).__init__()

	def draw(self, context, layout, node, text):
		if self.is_output == False and self.is_linked == False :
			layout.prop( self, 'default_value', text=text )
		else:
			layout.label(text='I32:'+text)
		
	def draw_color(self, context, node):
		return (0.6, 0.6, 0.3, 1.0)
		
	def f_getData(self):
		if self.is_linked == False :
			return self.default_value
		return engineLib.flexCAPI.f_取插座数据(ctypes.c_wchar_p(self.node.id_data.name), ctypes.c_wchar_p(self.node.name), ctypes.c_wchar_p(self.identifier))
		
	def f_setData(self, data):
		self.default_value = int(data)
		print("bug n1 -------------------------------------")
		f_socketInt32Update(self, None)
		
	def f_update(self):
		print("bug n2 -------------------------------------")
		f_socketInt32Update(self, None)






class C_Socket_I64(插座基类.C_Socket_基类):
	default_value = bpy.props.IntProperty(default=0, update=f_socketInt32Update)
	def __init__(self):
		super(C_Socket_I64, self).__init__()

	def draw(self, context, layout, node, text):
		if self.is_output == False and self.is_linked == False :
			layout.prop( self, 'default_value', text=text )
		else:
			layout.label(text='I64:'+text)
		
	def draw_color(self, context, node):
		return (0.6, 0.6, 0.3, 1.0)
		
	def f_getData(self):
		if self.is_linked == False :
			return self.default_value
		return engineLib.flexCAPI.f_取插座数据(ctypes.c_wchar_p(self.node.id_data.name), ctypes.c_wchar_p(self.node.name), ctypes.c_wchar_p(self.identifier))
		
	def f_setData(self, data):
		self.default_value = int(data)
		f_socketInt32Update(self, None)
		
	def f_update(self):
		f_socketInt32Update(self, None)




class C_Socket_UI32(插座基类.C_Socket_基类):
	default_value = bpy.props.IntProperty(default=0, update=f_socketInt32Update)
	def __init__(self):
		super(C_Socket_UI32, self).__init__()

	def draw(self, context, layout, node, text):
		if self.is_output == False and self.is_linked == False :
			layout.prop( self, 'default_value', text=text )
		else:
			layout.label(text='UI32:'+text)
		
	def draw_color(self, context, node):
		return (0.6, 0.6, 0.3, 1.0)
		
	def f_getData(self):
		if self.is_linked == False :
			return self.default_value
		return engineLib.flexCAPI.f_取插座数据(ctypes.c_wchar_p(self.node.id_data.name), ctypes.c_wchar_p(self.node.name), ctypes.c_wchar_p(self.identifier))
		
	def f_setData(self, data):
		self.default_value = int(data)
		f_socketInt32Update(self, None)
		
	def f_update(self):
		f_socketInt32Update(self, None)




class C_Socket_UI64(插座基类.C_Socket_基类):
	default_value = bpy.props.IntProperty(default=0, update=f_socketInt32Update)
	def __init__(self):
		super(C_Socket_UI64, self).__init__()

	def draw(self, context, layout, node, text):
		if self.is_output == False and self.is_linked == False :
			layout.prop( self, 'default_value', text=text )
		else:
			layout.label(text='UI64:'+text)
		
	def draw_color(self, context, node):
		return (0.6, 0.6, 0.3, 1.0)
		
	def f_getData(self):
		if self.is_linked == False :
			return self.default_value
		return engineLib.flexCAPI.f_取插座数据(ctypes.c_wchar_p(self.node.id_data.name), ctypes.c_wchar_p(self.node.name), ctypes.c_wchar_p(self.identifier))
		
	def f_setData(self, data):
		self.default_value = int(data)
		f_socketInt32Update(self, None)
		
	def f_update(self):
		f_socketInt32Update(self, None)








classes = (
	C_Socket_节点流程阀,

	C_Socket_Bool,
	
	C_Socket_F32,
	C_Socket_F64,

	C_Socket_I8,
	C_Socket_I32,
	C_Socket_I64,
	C_Socket_UI32,
	C_Socket_UI64,

)

def register():
	for c in classes:
		bpy.utils.register_class(c)	

def unregister():
	for c in classes:
		bpy.utils.unregister_class(c)
	





